<html>
<%@ page language="java" import="javazoom.upload.*,java.util.*,com.bluesky.drcp.presentation.web.*" %>

<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean">
  <jsp:setProperty name="upBean" property="storemodel"
   value="<%= UploadBean.MEMORYSTORE %>" />
</jsp:useBean>

<head>
<title>Plugin Uploading</title>
<style TYPE="text/css">
<!--
.style1 {
	font-size: 12px;
	font-family: Verdana;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">

<h3>Plugin Uploading</h3>
<p>please keep version same </p>
<ul class="style1">
<%
      if (MultipartFormDataRequest.isMultipartFormData(request))
      {
         // Uses MultipartFormDataRequest to parse the HTTP request.
         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
         String todo = null;
         if (mrequest != null) todo = mrequest.getParameter("todo");
	     if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
	     {
                Hashtable files = mrequest.getFiles();
                if ( (files != null) && (!files.isEmpty()) )
                {
                    UploadFile file = (UploadFile) files.get("uploadfile");
                    if (file != null) out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                    // Uses the bean now to store specified by jsp:setProperty at the top.
                    upBean.store(mrequest, "uploadfile");
                    System.out.println("is empty:"+upBean.getMemorystore().isEmpty());
                    javazoom.upload.parsing.CosUploadFile cosUploadFile = (javazoom.upload.parsing.CosUploadFile)upBean.getMemorystore().firstElement();

					String fileName = cosUploadFile.getFileName();
					String pluginName = fileName.substring(0,fileName.lastIndexOf('.'));
                    String version = mrequest.getParameter("version");
                    String description = mrequest.getParameter("description");                    
                    byte[] data = cosUploadFile.getData();

                    
					if(SaveFilePluginToDB.Save(getServletContext(),pluginName,version,description,data))
						out.println("<li>save plugin OK.");
					else
						out.println("<li>save plugin fail.");
                }
                else
                {
                  out.println("<li>No uploaded files");
                }
	     }
         else out.println("<BR> todo="+todo);
      }
%>
</ul>


<form method="post" name="upform" enctype="multipart/form-data">
  <table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
    <tr>
      <td align="left"><b>version</b></td>
      <td><input type="text" name="version" size="50"></td>
    </tr>
    <tr>
      <td align="left"><b>description</b></td>
      <td><input type="text" name="description" size="50"></td>
    </tr>
    <tr>
      <td align="left"><b>Plugin</b></td>
      <td align="left">
        <input type="file" name="uploadfile" size="50">
        </td>
    </tr>
   
    <tr>
      <td align="left">
		<input type="hidden" name="todo" value="upload">
        <input type="submit" name="Submit" value="Upload">
        <input type="reset" name="Reset" value="Cancel">
        </td>
    </tr>
  </table>  
</form>

</body>
</html>
